#!/usr/bin/env ruby
   
str = "35 C"

temp, scale = str.split(" ")

if temp !~ /-?[0-9]+/
    print temp, " is not valid.\n"
    exit 1
end

temp = temp.to_f

case scale
    when "C", "c"
        f = 1.8*temp + 32
    when "F", "f"
        c = (5.0/9.0)*(temp-32)
    else
        print "Must specify C or F.\n"
        exit 2
end

if c != nil
    print "#{c} in degrees C.\n"
else
    print "#{f} in degrees F.\n"
end
